package cs383.GradUnit;

import java.util.ArrayList;

public class cPlayer {
	private int chips;
	private int chipsInHand;
	private int chipsInRound;
	
	public boolean inHand;
	public boolean inGame;
	public boolean allIn;
	
	public ArrayList<Card> holeCards;
	
	/**
	 * Constructor for cPlayer
	 * 
	 * Creates a new instance of cPlayer.  Initializes data members.
	 * 
	 * @param startingChips The amount of chips the player starts with
	 */
	cPlayer(int startingChips){
		chips = startingChips;
		chipsInHand = 0;
		chipsInRound = 0;
		inHand = false;
		inGame = true;
		allIn = false;
		
		holeCards = new ArrayList();
	}
	
	/**
	 * Initializes the player's chip total
	 * 
	 * This method is used at the start of the game to initialize starting chip amounts.
	 * It can also be used for testing.
	 * 
	 * @param chipAmount
	 */
	void setChips(int chipAmount){
		chips = chipAmount;
	}
	
	/**
	 * Resets the amount of chips in the current round to 0
	 * 
	 * Called from cTable when the round number is incremented.  Used to keep track of how much
	 *   to bet if the player has to call a re-raise.  
	 */
	void resetChipsInRound(){
		chipsInRound = 0;
	}
	
	/**
	 * Resets the amount of chips in the current hand to 0
	 * 
	 * Called from cTable when a new hand is started.
	 */
	void resetChipsInHand(){
		chipsInHand = 0;
	}
	
	/**
	 * Gives the total amount of chips the player has left.
	 * 
	 * @return The amount of chips the player has.
	 */
	int getChipAmount(){
		if(chips < 0)
			return 0;
		else
			return chips;
	}
	
	/**
	 * Gives the amount of chips the player currently has in a hand
	 * 
	 * @return The amount of chips 
	 */
	int getChipsInHand(){
		if(chipsInHand < 0)
			return 0;
		else
			return chipsInHand;
	}
	
	/**
	 * Gives the amount of chips the player has in the current round of betting
	 * 
	 * @return The amount of chips in the current round of betting.
	 */
	int getChipsInRound(){
		if(chipsInRound < 0)
			return 0;
		else
			return chipsInRound;
	}
	
	/**
	 * removes the specified amount of chips from the player's chip count
	 * 
	 * This method is used to specify how much a player bets
	 * 
	 * @param chipAmount is the amount of chips to remove
	 */
	void takeChips(int chipAmount){
		if(chips - chipAmount > 0){
			chips -= chipAmount;
			chipsInHand += chipAmount;
			chipsInRound += chipAmount;
		}
		else{
			chipsInHand += chips;
			chipsInRound += chips;
			chips = 0;
		}
	}
	
	void refundChips(int chipAmount){
		chips += chipAmount;
		chipsInHand -= chipAmount;
		chipsInRound -= chipAmount;
	}
	void goAllIn(){
		chipsInHand += chips;
		chipsInRound += chips;
		chips = 0;
		allIn = true;
	}
	
	/**
	 * Awards a hand's pot to the player if they win
	 * 
	 * If the player is the winner of a hand, this method is called to add
	 *   the chips to the player's chip total
	 * 
	 * @param chipAmount The amount of chips the player won in the hand
	 */
	void awardChips(int chipAmount){
		if(chipAmount < 0)
			chips += 0;
		else
			chips += chipAmount;
	}
	
}
